﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using YFIN.View.ForeignExchangeServiceRef;
using System.Collections.ObjectModel;
using Visifire.Charts;

namespace YFIN.View.MarketTrend
{
    public partial class ForeignExchangeChart : UserControl
    {
        public ForeignExchangeChart()
        {
            InitializeComponent();
            LayoutRoot.Children.Add(new UserControl());
        }
        public void CreateChart(ObservableCollection<ModelForeignExchange> foreignExchange, int index)
        {
            // Create a new instance of Chart
            Chart chart = new Chart();

            // Set the chart width and height
            chart.Width = 550;
            chart.Height = 350;

            // Create a new instance of Title
            Title title = new Title();

            // Add title to Titles collection
            chart.Titles.Add(title);

            // Create a new instance of DataSeries
            DataSeries dataSeries = new DataSeries();

            // Set DataSeries property
            dataSeries.RenderAs = RenderAs.Line;

            // Create a DataPoint
            DataPoint dataPoint;

            foreach (var p in foreignExchange)
            {
                // Create a new instance of DataPoint
                dataPoint = new DataPoint();

                // Set YValue for a DataPoint
                dataPoint.AxisXLabel = p.Time.ToShortDateString();
                switch (index)
                {
                    case 0:
                        dataPoint.YValue = p.Dollar;
                        // Set title property
                        title.Text = "人民币兑美元报价";
                        break;
                    case 1:
                        dataPoint.YValue = p.Euro;
                        // Set title property
                        title.Text = "人民币兑欧元报价";
                        break;
                    case 2:
                        dataPoint.YValue = p.HKDollar;
                        // Set title property
                        title.Text = "人民币兑港元报价";
                        break;
                    case 3:
                        dataPoint.YValue = p.Yen;
                        // Set title property
                        title.Text = "人民币兑日元报价";
                        break;
                    case 4:
                        dataPoint.YValue = p.Pound;
                        // Set title property
                        title.Text = "人民币兑英镑报价";
                        break;
                    case 5:
                        dataPoint.YValue = p.ADollar;
                        title.Text = "人民币兑澳元报价";
                        break;
                    default:
                        dataPoint.YValue = p.CDollar;
                        // Set title property
                        title.Text = "人民币兑加元报价";
                        break;
                }

                // Add dataPoint to DataPoints collection
                dataSeries.DataPoints.Add(dataPoint);
            }

            // Add dataSeries to Series collection.
            chart.Series.Add(dataSeries);

            // Add chart to LayoutRoot
            LayoutRoot.Children[0] = chart;

        }
    }
}
